﻿using System.Xml;

namespace Jayden.Dll.Sc2.Descriptions.Zerg
{
	public class InjectActionDescription : CastActionDescription
	{
		protected InjectActionDescription(EntityDescription entity, EntityDescription build, string id, double energy)
			: base(entity, build, id, energy) { }
		public InjectActionDescription(EntityDescription entity, XmlNode node, string format = "{0}Inject{1}")
			: base(entity, node, format) { }

		public override bool IsExecutable(GameState state)
		{
			int running = (int)state.GetData(Id, 0);
			int bases = state.Bases;
			if (bases <= running)
				return false;
			return base.IsExecutable(state);
		}

		protected override void Cast(GameState state)
		{
			int running = (int)state.GetData(Id, 0);
			state.SetData(Id, running + 1);
			state.Add(Build, 4, 0, 4);
			state.Add(new DelayedActionDescription(this, state.Time + 40, delegate(GameState innerState)
			{
				int innerRunning = (int)innerState.GetData(Id, 0);
				innerState.SetData(Id, innerRunning - 1);
				innerState.Add(Build, -4, 4, 0);
			}, "LarvaeSpawned"));
		}
	}
}
